<script lang="ts">
import { defineComponent } from "vue";

export default defineComponent({
  props: {
    info: { type: Object, required: true },
  },
});
</script>

<template>
  <view class="note-item">
    <view class="note-item-cover" :style="{ height: `${info.heightRect}px` }">
      <view class="note-item-html" v-if="info.type === 3">
        <view class="note-item-html2">
          <rich-text :nodes="info.content" />
        </view>
      </view>
      <image class="note-item-img" v-else :src="info.img_url" lazy-load />
      <image
        class="note-item-video"
        v-if="info.type === 2"
        src="/static/community-note-video.png"
      />
    </view>
    <view class="note-item-content">
      <view class="note-item-name">{{ info.title }}</view>
      <view style="display: flex; align-items: center">
        <image
          class="note-item-avatar"
          :src="info.author_avatar"
          mode="aspectFill"
          lazy-load
        />
        <view class="note-item-author">{{ info.author_name }}</view>
        <slot />
      </view>
    </view>
  </view>
</template>

<style lang="scss">
.note-item {
  position: relative;

  .note-item-cover {
    position: relative;
  }

  .note-item-html {
    height: 100%;
    padding: 20rpx;
    border-radius: 20rpx 20rpx 0 0;
    background-color: #f4f4f4;
    box-sizing: border-box;
  }

  .note-item-html2 {
    height: 100%;
    font-size: 24rpx;
    color: #999999;
    line-height: 40rpx;
    overflow: hidden;
  }

  .note-item-img {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 20rpx 20rpx 0 0;
  }

  .note-item-video {
    position: absolute;
    top: 20rpx;
    right: 20rpx;
    width: 40rpx;
    height: 40rpx;
  }

  .note-item-content {
    padding: 20rpx;
    background-color: #ffffff;
    border-radius: 0 0 20rpx 20rpx;
  }

  .note-item-name {
    height: 80rpx;
    margin-bottom: 16rpx;
    font-size: 28rpx;
    color: #333333;
    line-height: 40rpx;
    font-weight: bold;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    text-overflow: ellipsis;
    overflow: hidden;
  }

  .note-item-avatar {
    flex-shrink: 0;
    width: 40rpx;
    height: 40rpx;
    border-radius: 50%;
  }

  .note-item-author {
    flex-grow: 1;
    min-width: 0;
    margin-left: 10rpx;
    font-size: 24rpx;
    color: #666666;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }
}
</style>